<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.global.js"></script>
</head>
<body>
  <div id="root">
    {{ count }} <button @click="add">add</button>
    <button @click="clear">清除watchEffect</button>
  </div>
</body>
<script type="module">
  const { createApp, reactive, ref, watchEffect } = window.Vue
  const app = createApp({
    setup(props) {
      const count = ref(100)

      const add = () => {
        count.value += 10
      }

      // 消除watchEffect副作用就是停止监听，并且返回值是停止监听的函数
      const stop = watchEffect(() => {
        // console.log(count)
        document.title = count.value
      })

      const clear = () => {
        stop()
      }

      return {
        count,
        add,
        clear
      }
    }
  })

  app.mount('#root')
</script>
</html>